home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / fl_boxtype.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  8.2 KB  |  287 lines

  1. //
  2. // "$Id: fl_boxtype.cxx,v 1.8 1999/01/07 19:17:36 mike Exp $"
  3. //
  4. // Box drawing code for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Box drawing code for the common box types and the table of
  27. // boxtypes.  Other box types are in seperate files so they are not
  28. // linked in if not used.
  29.  
  30. #include <FL/Fl.H>
  31. #include <FL/Fl_Widget.H>
  32. #include <FL/fl_draw.H>
  33. #include <config.h>
  34.  
  35. ////////////////////////////////////////////////////////////////
  36.  
  37. static uchar active_ramp[24] = {
  38.   FL_GRAY_RAMP+0, FL_GRAY_RAMP+1, FL_GRAY_RAMP+2, FL_GRAY_RAMP+3,
  39.   FL_GRAY_RAMP+4, FL_GRAY_RAMP+5, FL_GRAY_RAMP+6, FL_GRAY_RAMP+7,
  40.   FL_GRAY_RAMP+8, FL_GRAY_RAMP+9, FL_GRAY_RAMP+10,FL_GRAY_RAMP+11,
  41.   FL_GRAY_RAMP+12,FL_GRAY_RAMP+13,FL_GRAY_RAMP+14,FL_GRAY_RAMP+15,
  42.   FL_GRAY_RAMP+16,FL_GRAY_RAMP+17,FL_GRAY_RAMP+18,FL_GRAY_RAMP+19,
  43.   FL_GRAY_RAMP+20,FL_GRAY_RAMP+21,FL_GRAY_RAMP+22,FL_GRAY_RAMP+23};
  44. static uchar inactive_ramp[24] = {
  45.   43, 43, 44, 44,
  46.   44, 45, 45, 46,
  47.   46, 46, 47, 47,
  48.   48, 48, 48, 49,
  49.   49, 49, 50, 50,
  50.   51, 51, 52, 52};
  51. static int draw_it_active = 1;
  52. uchar *fl_gray_ramp() {return (draw_it_active?active_ramp:inactive_ramp)-'A';}
  53.  
  54. void fl_frame(const char* s, int x, int y, int w, int h) {
  55.   uchar *g = fl_gray_ramp();
  56.   if (h > 0 && w > 0) for (;*s;) {
  57.     // draw top line:
  58.     fl_color(g[*s++]);
  59.     fl_xyline(x, y, x+w-1);
  60.     y++; if (--h <= 0) break;
  61.     // draw left line:
  62.     fl_color(g[*s++]);
  63.     fl_yxline(x, y+h-1, y);
  64.     x++; if (--w <= 0) break;
  65.     // draw bottom line:
  66.     fl_color(g[*s++]);
  67.     fl_xyline(x, y+h-1, x+w-1);
  68.     if (--h <= 0) break;
  69.     // draw right line:
  70.     fl_color(g[*s++]);
  71.     fl_yxline(x+w-1, y+h-1, y);
  72.     if (--w <= 0) break;
  73.   }
  74. }
  75.  
  76. void fl_frame2(const char* s, int x, int y, int w, int h) {
  77.   uchar *g = fl_gray_ramp();
  78.   if (h > 0 && w > 0) for (;*s;) {
  79.     // draw bottom line:
  80.     fl_color(g[*s++]);
  81.     fl_xyline(x, y+h-1, x+w-1);
  82.     if (--h <= 0) break;
  83.     // draw right line:
  84.     fl_color(g[*s++]);
  85.     fl_yxline(x+w-1, y+h-1, y);
  86.     if (--w <= 0) break;
  87.     // draw top line:
  88.     fl_color(g[*s++]);
  89.     fl_xyline(x, y, x+w-1);
  90.     y++; if (--h <= 0) break;
  91.     // draw left line:
  92.     fl_color(g[*s++]);
  93.     fl_yxline(x, y+h-1, y);
  94.     x++; if (--w <= 0) break;
  95.   }
  96. }
  97.  
  98. void fl_no_box(int, int, int, int, Fl_Color) {}
  99.  
  100. void fl_thin_down_frame(int x, int y, int w, int h, Fl_Color) {
  101.   fl_frame2("WWHH",x,y,w,h);
  102. }
  103.  
  104. void fl_thin_down_box(int x, int y, int w, int h, Fl_Color c) {
  105.   fl_thin_down_frame(x,y,w,h,c);
  106.   fl_color(c); fl_rectf(x+1, y+1, w-2, h-2);
  107. }
  108.  
  109. void fl_thin_up_frame(int x, int y, int w, int h, Fl_Color) {
  110.   fl_frame2("HHWW",x,y,w,h);
  111. }
  112.  
  113. void fl_thin_up_box(int x, int y, int w, int h, Fl_Color c) {
  114.   fl_thin_up_frame(x,y,w,h,c);
  115.   fl_color(c); fl_rectf(x+1, y+1, w-2, h-2);
  116. }
  117.  
  118. void fl_up_frame(int x, int y, int w, int h, Fl_Color) {
  119. #if BORDER_WIDTH == 1
  120.   fl_frame2("HHWW",x,y,w,h);
  121. #else
  122. #if BORDER_WIDTH == 2
  123.   fl_frame2("AAUWMMTT",x,y,w,h);
  124. #else
  125.   fl_frame("AAAAWUJJUTNN",x,y,w,h);
  126. #endif
  127. #endif
  128. }
  129.  
  130. #define D1 BORDER_WIDTH
  131. #define D2 (BORDER_WIDTH+BORDER_WIDTH)
  132.  
  133. void fl_up_box(int x, int y, int w, int h, Fl_Color c) {
  134.   fl_up_frame(x,y,w,h,c);
  135.   fl_color(c); fl_rectf(x+D1, y+D1, w-D2, h-D2);
  136. }
  137.  
  138. void fl_down_frame(int x, int y, int w, int h, Fl_Color) {
  139. #if BORDER_WIDTH == 1
  140.   fl_frame2("WWHH",x,y,w,h);
  141. #else
  142. #if BORDER_WIDTH == 2
  143.   fl_frame2("UWMMPPAA",x,y,w,h);
  144. #else
  145.   fl_frame("NNTUJJUWAAAA",x,y,w,h);
  146. #endif
  147. #endif
  148. }
  149.  
  150. void fl_down_box(int x, int y, int w, int h, Fl_Color c) {
  151.   fl_down_frame(x,y,w,h,c);
  152.   fl_color(c); fl_rectf(x+D1, y+D1, w-D2, h-D2);
  153. }
  154.  
  155. void fl_engraved_frame(int x, int y, int w, int h, Fl_Color) {
  156.   fl_frame("HHWWWWHH",x,y,w,h);
  157. }
  158.  
  159. void fl_engraved_box(int x, int y, int w, int h, Fl_Color c) {
  160.   fl_engraved_frame(x,y,w,h,c);
  161.   fl_color(c); fl_rectf(x+2, y+2, w-4, h-4);
  162. }
  163.  
  164. void fl_embossed_frame(int x, int y, int w, int h, Fl_Color) {
  165.   fl_frame("WWHHHHWW",x,y,w,h);
  166. }
  167.  
  168. void fl_embossed_box(int x, int y, int w, int h, Fl_Color c) {
  169.   fl_embossed_frame(x,y,w,h,c);
  170.   fl_color(c); fl_rectf(x+2, y+2, w-4, h-4);
  171. }
  172.  
  173. void fl_rectbound(int x, int y, int w, int h, Fl_Color bgcolor) {
  174.   fl_color(FL_BLACK); fl_rect(x, y, w, h);
  175.   fl_color(bgcolor); fl_rectf(x+1, y+1, w-2, h-2);
  176. }
  177. #define fl_border_box fl_rectbound
  178.  
  179. void fl_rectf(int x, int y, int w, int h, Fl_Color c) {
  180.   fl_color(c);
  181.   fl_rectf(x, y, w, h);
  182. }
  183.  
  184. void fl_border_frame(int x, int y, int w, int h, Fl_Color c) {
  185.   fl_color(c);
  186.   fl_rect(x, y, w, h);
  187. }
  188.  
  189. ////////////////////////////////////////////////////////////////
  190.  
  191. static struct {
  192.   Fl_Box_Draw_F *f;
  193.   uchar dx, dy, dw, dh;
  194. } fl_box_table[] = {
  195. // must match list in Enumerations.H!!!
  196.   {fl_no_box,        0,0,0,0},        
  197.   {fl_rectf,        0,0,0,0}, // FL_FLAT_BOX
  198.   {fl_up_box,        D1,D1,D2,D2},
  199.   {fl_down_box,        D1,D1,D2,D2},
  200.   {fl_up_frame,        D1,D1,D2,D2},
  201.   {fl_down_frame,    D1,D1,D2,D2},
  202.   {fl_thin_up_box,    1,1,2,2},
  203.   {fl_thin_down_box,    1,1,2,2},
  204.   {fl_thin_up_frame,    1,1,2,2},
  205.   {fl_thin_down_frame,    1,1,2,2},
  206.   {fl_engraved_box,    2,2,4,4},
  207.   {fl_embossed_box,    2,2,4,4},
  208.   {fl_engraved_frame,    2,2,4,4},
  209.   {fl_embossed_frame,    2,2,4,4},
  210.   {fl_border_box,    1,1,2,2},
  211.   {fl_border_box,    1,1,2,2}, // _FL_SHADOW_BOX,
  212.   {fl_border_frame,    1,1,2,2},
  213.   {fl_border_frame,    1,1,2,2}, // _FL_SHADOW_FRAME,
  214.   {fl_border_box,    1,1,2,2}, // _FL_ROUNDED_BOX,
  215.   {fl_border_box,    1,1,2,2}, // _FL_RSHADOW_BOX,
  216.   {fl_border_frame,    1,1,2,2}, // _FL_ROUNDED_FRAME
  217.   {fl_rectf,        0,0,0,0}, // _FL_RFLAT_BOX,
  218.   {fl_up_box,        3,3,6,6}, // _FL_ROUND_UP_BOX
  219.   {fl_down_box,        3,3,6,6}, // _FL_ROUND_DOWN_BOX,
  220.   {fl_up_box,        0,0,0,0}, // _FL_DIAMOND_UP_BOX
  221.   {fl_down_box,        0,0,0,0}, // _FL_DIAMOND_DOWN_BOX
  222.   {fl_border_box,    1,1,2,2}, // _FL_OVAL_BOX,
  223.   {fl_border_box,    1,1,2,2}, // _FL_OVAL_SHADOW_BOX,
  224.   {fl_border_frame,    1,1,2,2}, // _FL_OVAL_FRAME
  225.   {fl_rectf,        0,0,0,0}, // _FL_OVAL_FLAT_BOX,
  226.   {fl_up_box,        3,3,6,6}, // FL_FREE_BOX+0
  227.   {fl_down_box,        3,3,6,6}, // FL_FREE_BOX+1
  228.   {fl_up_box,        3,3,6,6}, // FL_FREE_BOX+2
  229.   {fl_down_box,        3,3,6,6}, // FL_FREE_BOX+3
  230.   {fl_up_box,        3,3,6,6}, // FL_FREE_BOX+4
  231.   {fl_down_box,        3,3,6,6}, // FL_FREE_BOX+5
  232.   {fl_up_box,        3,3,6,6}, // FL_FREE_BOX+6
  233.   {fl_down_box,        3,3,6,6}, // FL_FREE_BOX+7
  234. };
  235.  
  236. int Fl::box_dx(Fl_Boxtype t) {return fl_box_table[t].dx;}
  237. int Fl::box_dy(Fl_Boxtype t) {return fl_box_table[t].dy;}
  238. int Fl::box_dw(Fl_Boxtype t) {return fl_box_table[t].dw;}
  239. int Fl::box_dh(Fl_Boxtype t) {return fl_box_table[t].dh;}
  240.  
  241. void fl_internal_boxtype(Fl_Boxtype t, Fl_Box_Draw_F* f) {fl_box_table[t].f=f;}
  242.  
  243. void Fl::set_boxtype(Fl_Boxtype t, Fl_Box_Draw_F* f,
  244.               uchar a, uchar b, uchar c, uchar d) {
  245.   fl_box_table[t].f=f;
  246.   fl_box_table[t].dx = a;
  247.   fl_box_table[t].dy = b;
  248.   fl_box_table[t].dw = c;
  249.   fl_box_table[t].dh = d;
  250. }
  251.  
  252. void Fl::set_boxtype(Fl_Boxtype t, Fl_Boxtype f) {
  253.   fl_box_table[t] = fl_box_table[f];
  254. }
  255.  
  256. void fl_draw_box(Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c) {
  257.   if (t) fl_box_table[t].f(x,y,w,h,c);
  258. }
  259.  
  260. //extern Fl_Widget *fl_boxcheat; // hack set by Fl_Window.C
  261.  
  262. void Fl_Widget::draw_box() const {
  263.   int t = box_;
  264.   if (!t) return;
  265. //   if (this == fl_boxcheat) {
  266. //     fl_boxcheat = 0;
  267. //     if (t == FL_FLAT_BOX) return;
  268. //     t += 2; // convert box to frame
  269. //   }
  270.   draw_box((Fl_Boxtype)t, x_, y_, w_, h_, (Fl_Color)color_);
  271. }
  272.  
  273. void Fl_Widget::draw_box(Fl_Boxtype b, Fl_Color c) const {
  274.   draw_box(b, x_, y_, w_, h_, c);
  275. }
  276.  
  277. void Fl_Widget::draw_box(Fl_Boxtype b, int x, int y, int w, int h, Fl_Color c)
  278. const {
  279.   draw_it_active = active_r();
  280.   fl_box_table[b].f(x, y, w, h, c);
  281.   draw_it_active = 1;
  282. }
  283.  
  284. //
  285. // End of "$Id: fl_boxtype.cxx,v 1.8 1999/01/07 19:17:36 mike Exp $".
  286. //
  287.